package com.da.javatest.util;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneOffset;
import java.util.Date;

/**
 * @author chenlida
 * @date 2018/11/7 17:27
 * @Description:
 */
public class OvertimeUtil {
    private static DateFormat dfm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public static String calculationTime(Date startTime, Date endTime) {
        String result = "";
        int time = (int)(endTime.getTime() - startTime.getTime());
        time /= 60000;
        //System.out.println(time);
        if (time / 1440 > 0) {
            result += (time / 1440) + "d";
        } else {
            result += "0d";
        }

        time %= 1440;
        if (time / 60 > 0) {
            result += (time / 60) + "h";
        } else {
            result += "0h";
        }

        time %= 60;
        result += time + "m";

        return result;
    }

    public static void main(String[] args) throws ParseException {
        String r = calculationTime(dfm.parse("2018-11-05 12:08:00"), dfm.parse("2018-11-08 16:12:00"));
        String r1 = calculationTime(dfm.parse("2018-11-08 12:08:00"), dfm.parse("2018-11-08 14:14:00"));
        String r2 = calculationTime(dfm.parse("2018-11-04 12:08:00"), dfm.parse("2018-11-08 12:19:00"));
        System.out.println(r);
        System.out.println(r1);
        System.out.println(r2);

        System.out.println(LocalDate.now());
        System.out.println(LocalTime.now());
        System.out.println(LocalDateTime.now());
        System.out.println(LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8")));
        System.out.println("哈哈哈");
    }
}
